unit UThemeAdd;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UThemeAddEditBase, cxGraphics,
  cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxContainer, cxEdit,
  dxSkinsCore, dxSkinOffice2016Colorful, Vcl.Menus, System.ImageList,
  Vcl.ImgList, cxImageList, Vcl.StdCtrls, cxButtons, Vcl.ExtCtrls,
  dxGDIPlusClasses, cxImage, cxMaskEdit, cxSpinEdit, cxTextEdit, cxLabel,
  cxClasses;

type
  TfrmThemeAdd = class(TfrmThemeAddEditBase)
    procedure btnSaveClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmThemeAdd: TfrmThemeAdd;

implementation

uses
  UCommonConst, UCommonFunSqlite;

{$R *.dfm}

procedure TfrmThemeAdd.btnSaveClick(Sender: TObject);
var
  sSql, sThemeName: string;
  iThemeID, iDuration: Integer;
begin
  inherited;

  sThemeName := Trim(edtName.Text);
  if sThemeName.IsEmpty then
  begin
    MsgBoxDefault(RESTHEMENAMEEMPTY);
    edtName.SetFocus;
    Abort;
  end;

  iDuration := edtDuration.Value;

  if checkExistInDB('ThemeData', 'ThemeName', sThemeName) then
  begin
    MsgBoxDefault(RESTHEMEEXIST);
    edtName.SetFocus;
    Abort;
  end;

  iThemeID := getMaxRecordNum('ThemeData', 'ThemeID') + 1;

  sSql := 'insert into ThemeData (ThemeID,ThemeName,Duration) values ('
        + QuotedStr(IntToStr(iThemeID)) + ','
        + QuotedStr(sThemeName) + ','
        + QuotedStr(IntToStr(iDuration))
        + ')';

  if ExecSql(sSql) then
  begin
    edtName.Clear;

    SendMessage(FParentHandle, WM_REFRESHDATA, 0, 0);

    MsgBoxDefault(RESSAVESUCCESS);
  end
  else
    MsgBoxDefault(RESSAVEFAIL);
end;

end.
